-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(c-api) Implement wasm_exporttype_delete
#1685
Conversation
7443b30
to
fdb0772
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! The one thing I'd want to confirm before shipping this is the ownership of wasm_exporttype_t
, this looks like it has a legacy implementation so I'm a bit skeptical...
Yeah, exporttype_t owns both the things passed to it in new, so currently this implementation will leak memory because they're just stored as NonNull
and never freed.
I believe it is up to the user to free the Thoughts? |
`wasm_exporttype_t` has 2 fields: `name` and `extern_type`. Both are of kind `NonNull`. When `wasm_exporttype_t` is dropped, nor `name` nor `extern_type` are going to be dropped. To avoid leaking data, this patch adds a new field: `owns_fields`: * When `wasm_exporttype_t` is built from `wasm_exportype_new`, this field is set to `false` because `name` and `extern_type` are received by pointer, and its the responsibility of the caller to free them, * When `wasm_exporttype_t` is built from the `From<&ExportType>` implementation, _we_ create `name` and `extern_type` to then leak them. In this case, it is safe to reconstruct proper `Box`es to finally drop them.
Note: That's a little more trickier actually. It's likely that the The solution would be to add an See my patch above: f24a34b |
bors r+ |
Build succeeded: |
This PR implements the destructor for
wasm_exporttype_t
.